/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.core.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.core.dao.HumanDAO;
import com.core.database.Manager;
import com.core.entities.Human;
import com.core.exception.DAOException;

/**
 * 
 * @author himanasser
 */
public class HumanDAOImpl implements HumanDAO {
		Human human = new Human();
		ArrayList<Human> humansList = new ArrayList<Human>();


	Connection connection = null;
	private static HumanDAOImpl instance=null;
	public static HumanDAOImpl getInstance(){
		if(instance==null){
			instance=new HumanDAOImpl();
		}
		return instance;
	}

	@Override
	public Human findByFirst_name(String first_name) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE first_name = '"
					+ first_name + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public Human findBySecond_name(String second_name) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE second_name = '"
					+ second_name + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public Human findByThird_name(String third_name) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE third_name = '"
					+ third_name + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public Human findByLast_name(String last_name) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE last_name = '" + last_name
					+ "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public Human findByBirthdate(String birthdate) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE birthdate = '" + birthdate
					+ "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public Human findByAddress(String address) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE address = '" + address
					+ "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public Human findByMobile_phone(String mobile_phone) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE mobile_phone = '"
					+ mobile_phone + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public Human findByLand_phone(String land_phone) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE land_phone = '"
					+ land_phone + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public Human findByEmail(String email) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE email = '" + email + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public Human findByRole(String role) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE role = '" + role + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public Human findByUsername(String username) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE username = '" + username
					+ "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;

	}

	@Override
	public Human findByPassword(String password) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE password = '" + password
					+ "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public List<Human> findByCity_id(int city_id) throws DAOException {
		Human human = new Human();
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE city_id = '" + city_id
					+ "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				human.setId(rs.getInt(1));
				human.setFirst_name(rs.getString(2));
				human.setSecond_name(rs.getString(3));
				human.setThird_name(rs.getString(4));
				human.setLast_name(rs.getString(5));
				human.setBirthdate(rs.getString(6));
				human.setAddress(rs.getString(7));
				human.setMobile_phone(rs.getString(8));
				human.setLand_phone(rs.getString(9));
				human.setEmail(rs.getString(10));
				human.setRole(rs.getString(11));
				human.setUsername(rs.getString(12));
				human.setPassword(rs.getString(13));
				human.setCity_id(rs.getInt(14));
				human.setNational_id_number(rs.getString(15));
				human.setSalary(rs.getString(16));
				human.setJob_id(rs.getInt(17));
				human.setQualification_id(rs.getInt(18));
				human.setDepartment_id(rs.getInt(19));

				humansList.add(human);

			}
		} catch (SQLException s) {
			s.printStackTrace();
		}
		return humansList;
	}

	@Override
	public Human findByNational_id_number(String national_id_number)
			throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE national_id_number = '"
					+ national_id_number + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public Human findBySalary(String salary) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE salary = '" + salary + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public List<Human> findByJob_id(int job_id) throws DAOException {

		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE job_id = '" + job_id + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				human.setId(rs.getInt(1));
				human.setFirst_name(rs.getString(2));
				human.setSecond_name(rs.getString(3));
				human.setThird_name(rs.getString(4));
				human.setLast_name(rs.getString(5));
				human.setBirthdate(rs.getString(6));
				human.setAddress(rs.getString(7));
				human.setMobile_phone(rs.getString(8));
				human.setLand_phone(rs.getString(9));
				human.setEmail(rs.getString(10));
				human.setRole(rs.getString(11));
				human.setUsername(rs.getString(12));
				human.setPassword(rs.getString(13));
				human.setCity_id(rs.getInt(14));
				human.setNational_id_number(rs.getString(15));
				human.setSalary(rs.getString(16));
				human.setJob_id(rs.getInt(17));
				human.setQualification_id(rs.getInt(18));
				human.setDepartment_id(rs.getInt(19));

				humansList.add(human);

			}
		} catch (SQLException s) {
			s.printStackTrace();
		}
		return humansList;
	}

	@Override
	public List<Human> findByQualification_id(int qalification_id)
			throws DAOException {

		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE qalification_id = '"
					+ qalification_id + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				human.setId(rs.getInt(1));
				human.setFirst_name(rs.getString(2));
				human.setSecond_name(rs.getString(3));
				human.setThird_name(rs.getString(4));
				human.setLast_name(rs.getString(5));
				human.setBirthdate(rs.getString(6));
				human.setAddress(rs.getString(7));
				human.setMobile_phone(rs.getString(8));
				human.setLand_phone(rs.getString(9));
				human.setEmail(rs.getString(10));
				human.setRole(rs.getString(11));
				human.setUsername(rs.getString(12));
				human.setPassword(rs.getString(13));
				human.setCity_id(rs.getInt(14));
				human.setNational_id_number(rs.getString(15));
				human.setSalary(rs.getString(16));
				human.setJob_id(rs.getInt(17));
				human.setQualification_id(rs.getInt(18));
				human.setDepartment_id(rs.getInt(19));

				humansList.add(human);
			}
		} catch (SQLException s) {
			s.printStackTrace();
		}
		return humansList;
	}

	@Override
	public List<Human> findByDepartment_id(int department_id) throws DAOException {

		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE department_id = '"
					+ department_id + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				human.setId(rs.getInt(1));
				human.setFirst_name(rs.getString(2));
				human.setSecond_name(rs.getString(3));
				human.setThird_name(rs.getString(4));
				human.setLast_name(rs.getString(5));
				human.setBirthdate(rs.getString(6));
				human.setAddress(rs.getString(7));
				human.setMobile_phone(rs.getString(8));
				human.setLand_phone(rs.getString(9));
				human.setEmail(rs.getString(10));
				human.setRole(rs.getString(11));
				human.setUsername(rs.getString(12));
				human.setPassword(rs.getString(13));
				human.setCity_id(rs.getInt(14));
				human.setNational_id_number(rs.getString(15));
				human.setSalary(rs.getString(16));
				human.setJob_id(rs.getInt(17));
				human.setQualification_id(rs.getInt(18));
				human.setDepartment_id(rs.getInt(19));

				humansList.add(human);

			}
		} catch (SQLException s) {
			s.printStackTrace();
		}
		return humansList;
	}

	@Override
	public void insert(Human o) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "INSERT INTO human (first_name, second_name, third_name, last_name, birthdate, "
					+ "address, mobile_phone, land_phone, email, role, username, password, city_id, "
					+ "national_id_number, salary, job_id, qualification_id, department_id) "
					+ "VALUE(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
			PreparedStatement ps = connection.prepareStatement(sql);
			ps.setString(1, o.getFirst_name());
			ps.setString(2, o.getSecond_name());
			ps.setString(3, o.getThird_name());
			ps.setString(4, o.getLast_name());
			ps.setString(5, o.getBirthdate());
			ps.setString(6, o.getAddress());
			ps.setString(7, o.getMobile_phone());
			ps.setString(8, o.getLand_phone());
			ps.setString(9, o.getEmail());
			ps.setString(10, o.getRole());
			ps.setString(11, o.getUsername());
			ps.setString(12, o.getPassword());
			ps.setInt(13, o.getCity_id());
			ps.setString(14, o.getNational_id_number());
			ps.setString(15, o.getSalary());
			ps.setInt(16, o.getJob_id());
			ps.setInt(17, o.getQualification_id());
			ps.setInt(18, o.getDepartment_id());

			int result = ps.executeUpdate();
			if (result != 1) {
				throw new SQLException("no row inserted!");
			}
			
		} 
		catch (Exception ex) {
			ex.printStackTrace();
			throw new RuntimeException("Cannot add new Human", ex);
		} 
		finally {
			Manager.closeConnection(connection);
		}
	}

	@Override
	public Human findById(int id) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = "SELECT * FROM human WHERE id = '" + id + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			int count = 0;
			
			while (rs.next()) {
				count++;
				if (count == 1) {
					human.setId(rs.getInt(1));
					human.setFirst_name(rs.getString(2));
					human.setSecond_name(rs.getString(3));
					human.setThird_name(rs.getString(4));
					human.setLast_name(rs.getString(5));
					human.setBirthdate(rs.getString(6));
					human.setAddress(rs.getString(7));
					human.setMobile_phone(rs.getString(8));
					human.setLand_phone(rs.getString(9));
					human.setEmail(rs.getString(10));
					human.setRole(rs.getString(11));
					human.setUsername(rs.getString(12));
					human.setPassword(rs.getString(13));
					human.setCity_id(rs.getInt(14));
					human.setNational_id_number(rs.getString(15));
					human.setSalary(rs.getString(16));
					human.setJob_id(rs.getInt(17));
					human.setQualification_id(rs.getInt(18));
					human.setDepartment_id(rs.getInt(19));

				}
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
		return human;
	}

	@Override
	public List<Human> findAll() throws DAOException {

		try {
			connection = Manager.getConnection();
			String sql = " SELECT * FROM human ";
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				human.setId(rs.getInt(1));
				human.setFirst_name(rs.getString(2));
				human.setSecond_name(rs.getString(3));
				human.setThird_name(rs.getString(4));
				human.setLast_name(rs.getString(5));
				human.setBirthdate(rs.getString(6));
				human.setAddress(rs.getString(7));
				human.setMobile_phone(rs.getString(8));
				human.setLand_phone(rs.getString(9));
				human.setEmail(rs.getString(10));
				human.setRole(rs.getString(11));
				human.setUsername(rs.getString(12));
				human.setPassword(rs.getString(13));
				human.setCity_id(rs.getInt(14));
				human.setNational_id_number(rs.getString(15));
				human.setSalary(rs.getString(16));
				human.setJob_id(rs.getInt(17));
				human.setQualification_id(rs.getInt(18));
				human.setDepartment_id(rs.getInt(19));

				humansList.add(human);

			}
		} catch (SQLException s) {
			s.printStackTrace();
		}
		return humansList;
	}

	@Override
	public void delete(int id) throws DAOException {
		try {
			connection = Manager.getConnection();
			String sql = " DELETE FROM human WHERE id = '" + id + "'";
			PreparedStatement ps = connection.prepareStatement(sql);
			int result = ps.executeUpdate();
			if (result != 1) {
				ps.setString(1, human.getFirst_name());
				ps.setString(2, human.getSecond_name());
				ps.setString(3, human.getThird_name());
				ps.setString(4, human.getLast_name());
				ps.setString(5, human.getBirthdate());
				ps.setString(6, human.getAddress());
				ps.setString(7, human.getMobile_phone());
				ps.setString(8, human.getLand_phone());
				ps.setString(9, human.getEmail());
				ps.setString(10, human.getRole());
				ps.setString(11, human.getUsername());
				ps.setString(12, human.getPassword());
				ps.setInt(13, human.getCity_id());
				ps.setString(14, human.getNational_id_number());
				ps.setString(15, human.getSalary());
				ps.setInt(16, human.getJob_id());
				ps.setInt(17, human.getQualification_id());
				ps.setInt(18, human.getDepartment_id());
			}

		} catch (SQLException s) {
			s.printStackTrace();

		}
	}

	@Override
	public void update(Human o) throws DAOException {

		try {
			connection = Manager.getConnection();
			String sql = "UPDATE human SET first_name = '" + o.getFirst_name()
					+ " ', second_name = '" + o.getSecond_name()
					+ " ', third_name = '" + o.getThird_name()
					+ " ', last_name = '" + o.getLast_name()
					+ " ', birthdate = '" + o.getBirthdate()
					+ " ', address = '" + o.getAddress()
					+ " ', mobile_phone = '" + o.getMobile_phone()
					+ " ', land_phone = '" + o.getLand_phone()
					+ " ', email = '" + o.getEmail() 
					+ " ', role = '"+ o.getRole() 
					+ " ', username = '" + o.getUsername()
					+ " ', password = '" + o.getPassword() 
					+ " ', city_id = '"+ o.getCity_id() 
					+ " ', national_id_number = '"+ o.getNational_id_number() 
					+ " ', salary = '"+ o.getSalary() 
					+ " ', job_id = '" + o.getJob_id()
					+ " ', qualification_id = '" + o.getQualification_id()
					+ " ', department_id = '" + o.getDepartment_id()
					+ "' WHERE id = " + o.getId();
			PreparedStatement ps = connection.prepareStatement(sql);
			int result = ps.executeUpdate(sql);

			if (result != 1) {
				ps.setString(1, o.getFirst_name());
				ps.setString(2, o.getSecond_name());
				ps.setString(3, o.getThird_name());
				ps.setString(4, o.getLast_name());
				ps.setString(5, o.getBirthdate());
				ps.setString(6, o.getAddress());
				ps.setString(7, o.getMobile_phone());
				ps.setString(8, o.getLand_phone());
				ps.setString(9, o.getEmail());
				ps.setString(10, o.getRole());
				ps.setString(11, o.getUsername());
				ps.setString(12, o.getPassword());
				ps.setInt(13, o.getCity_id());
				ps.setString(14, o.getNational_id_number());
				ps.setString(15, o.getSalary());
				ps.setInt(16, o.getJob_id());
				ps.setInt(17, o.getQualification_id());
				ps.setInt(18, o.getDepartment_id());
			}

		} catch (SQLException s) {
			s.printStackTrace();
		}
	}
}
